/**
 post获取接口数据
 **/
layui.define(["layer", "jquery"], function (exports) {
    var $ = layui.$;
    var layer = layui.layer;
    var obj = {
        test: function (msg) {
            alert(msg+'111');
        },
        // header：php的header（固定） data:请求数据（json） callback：回调
        ajaxData: function (method, url, data, callback) {
            var loading = layer.load(1);
            $.ajax({
                type: method,
                //contentType: "application/json",
                url: url,
                dataType: 'json',
                data: data, //请求的附加参数，用json对象
                success: function (res) {
                    // console.log(res);
                    // if(res.errorCode != 0){
                    //     layer.msg(res.message, {icon: 2,time:2000});
                    //     return false;
                    // }
                    layer.close(loading);
                    //var msg = '成功';
                    if (typeof callback === 'function') {
                        callback(res);
                    }
                },
                error: function (errorBack) {
                    layer.close(loading);

                    if(errorBack.status == 419){
                        location.reload(true);
                        parent.location.reload(true);
                    }else{
                        layer.msg("error:请求错误", {icon: 5});
                    }
                    return false;
                    //window.location.reload();
                }
            });
        }
    };

    exports('ajaxData', obj);
});